﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ITSTOREBLL;
using ITStore.ViewModels;
using PagedList;


namespace ITStore.Controllers
{
    public class HomeController : Controller
    {
        private ITStoreEntities db = new ITStoreEntities();

        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult faqs()
        {
            return View();
        }
        

        public ActionResult checkout()
        {
            return View();
        }

        public ActionResult contact()
        {
            return View();
        }

        public ActionResult MoiNhat(int? page)
        {
            var SPMoi = from SPM in db.SanPhams
                        select SPM;
            SPMoi = SPMoi.OrderByDescending(s => s.sp_ID);
            int pageSize = 6;
            int pageNumber = (page ?? 1);
            return View(SPMoi.ToPagedList(pageNumber, pageSize));
        }

        public ActionResult XemNhieuNhat(int? page)
        {
            var SPMoi = from SPM in db.SanPhams
                        select SPM;
            SPMoi = SPMoi.OrderByDescending(s => s.sp_LuotXem);
            int pageSize = 6;
            int pageNumber = (page ?? 1);
            return View(SPMoi.ToPagedList(pageNumber, pageSize));
        }

        public ActionResult KhuyenMai(int? page)
        {
            var SPMoi = from SPM in db.SanPhams
                        where SPM.sp_KhuyenMai == 1
                        select SPM;
            int pageSize = 6;
            int pageNumber = (page ?? 1);
            return View(SPMoi.OrderBy(sp => sp.sp_ID).ToPagedList(pageNumber, pageSize));
        }
    }
}
